package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkGenerateDialog

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TempletGrammarSpecificListInfor
import kotlinx.android.synthetic.main.aibk_adapter_item_specific_analysis.view.*
import java.math.BigDecimal

class AibkSpecificAnalysisAdapter(
        val activity: AppCompatActivity,
        val templetGrammarSpecificListInfor: TempletGrammarSpecificListInfor,
        val indexA:Int,
        val indexB:Int,
        val isAllAnalysis:Boolean
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_specific_analysis, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        if(position == 0){
            var testLevel = 0
            if(isAllAnalysis){
                testLevel= templetGrammarSpecificListInfor[indexA].TestLevel
            }else {
                testLevel = templetGrammarSpecificListInfor[indexA].SubTopicList[indexB].TestLevel
            }
            //显示测试概率
            if(testLevel == 1) {
                holder.convertView.SpecificAnalysisAssessment.text = "常考"
                holder.convertView.SpecificAnalysisAssessment.setTextColor(activity.resources.getColor(R.color.lancoooGreen))
            }else if(testLevel == 2) {
                holder.convertView.SpecificAnalysisAssessment.text = "次常考"
                holder.convertView.SpecificAnalysisAssessment.setTextColor(activity.resources.getColor(R.color.lancoooBlue))
            }else if(testLevel == 3) {
                holder.convertView.SpecificAnalysisAssessment.text = "一般"
                holder.convertView.SpecificAnalysisAssessment.setTextColor(activity.resources.getColor(R.color.lancoooRed))
            }
            holder.convertView.SpecificAnalysisTitle.text = "测试概率"
        }else if(position == 1){
            var scoreRate = 0.0
            if(isAllAnalysis){
                scoreRate = templetGrammarSpecificListInfor[indexA].ScoreRate
            }else {
                scoreRate = templetGrammarSpecificListInfor[indexA].SubTopicList[indexB].ScoreRate
            }
            //显示分值占比
            val scoreRateX = LancooMethod.getScoreRate(scoreRate,2)
            holder.convertView.SpecificAnalysisAssessment.text = scoreRateX
            holder.convertView.SpecificAnalysisAssessment.setTextColor(activity.resources.getColor(R.color.lancoooOrange))
            holder.convertView.SpecificAnalysisTitle.text = "分值占比"
        }else if(position == 2){
            var masteryLevel = 0
            if(isAllAnalysis){
                masteryLevel = templetGrammarSpecificListInfor[indexA].MasteryLevel
            }else {
                masteryLevel = templetGrammarSpecificListInfor[indexA].SubTopicList[indexB].MasteryLevel
            }
            //显示掌握程度
            if(masteryLevel == 1) {
                holder.convertView.SpecificAnalysisAssessment.text = "扎实"
                holder.convertView.SpecificAnalysisAssessment.setTextColor(activity.resources.getColor(R.color.lancoooGreen))
            }else if(masteryLevel == 2) {
                holder.convertView.SpecificAnalysisAssessment.text = "一般"
                holder.convertView.SpecificAnalysisAssessment.setTextColor(activity.resources.getColor(R.color.lancoooBlue))
            }else if(masteryLevel == 3) {
                holder.convertView.SpecificAnalysisAssessment.text = "较差"
                holder.convertView.SpecificAnalysisAssessment.setTextColor(activity.resources.getColor(R.color.lancoooRed))
            }
            holder.convertView.SpecificAnalysisTitle.text = "掌握程度"
        }
    }

    override fun getItemCount(): Int {
        return 3
    }

}